package bluerain.io.adapter.ui;

import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import org.w3c.dom.Text;

import bluerain.io.adapter.R;

/**
 * Created by foredawn on 15-9-11.
 * 扩展BaseAdapter实现最大的adapter控制权
 */
public class BaseAdapterTest extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.base_adapter_test);

        BaseAdapter adapter = new BaseAdapter() {
            @Override
            public int getCount() {
                //返回列表项的总数
                return 40;
            }

            @Override
            public Object getItem(int position) {
                return null;
            }

            //重写此方法 将返回值作为列表项的ID
            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                //创建一个Linear布局
                LinearLayout linearLayout = new LinearLayout(BaseAdapterTest.this);
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                //创建一个ImgView
                ImageView img = new ImageView(BaseAdapterTest.this);
                img.setImageResource(R.drawable.li_bai);
                //创建一个TextView
                TextView text = new TextView(BaseAdapterTest.this);
                text.setTextSize(20);
                text.setTextColor(Color.RED);
                text.setText("第" + position + "个列表项");//文本内容为列表项位置
                //将View添加进入布局中
                linearLayout.addView(img);
                linearLayout.addView(text);
                //返回该布局
                return linearLayout;
            }
        };
        ((ListView) findViewById(R.id.baseList)).setAdapter(adapter);
    }
}
